//
//  ZCPlayMusicViewController.m
//  VoiceMusic
//
//  Created by dllo on 15/10/19.
//  Copyright © 2015年 zhangdeyu. All rights reserved.
//

#import "ZCPlayMusicViewController.h"
#import <Masonry.h>
#import "ZCMainModel.h"
#import "ZCPlayMusicTool.h"
#import <UMSocial.h>
#import "ZCDownLoadTool.h"
@interface ZCPlayMusicViewController ()<UITableViewDataSource,UITableViewDelegate,UMSocialUIDelegate>
//播放列表
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *headButton;
@property (nonatomic, strong) NSMutableArray *listArr;
@property (nonatomic ,assign) BOOL isList;

//播放UI
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIButton * perButton;
@property (nonatomic, strong) UIButton * playButton;
@property (nonatomic, strong) UIButton * nextButton;

@property (nonatomic, strong) UIButton *listButton;


@property (nonatomic, strong) UISlider *slider;
//进度条
@property (nonatomic, strong) UIProgressView *progress;

//是否播放
@property (nonatomic, assign) BOOL isplay;
@property (nonatomic, assign) BOOL isValue;

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *singerLabel;
@property (nonatomic, copy) NSString *url;

@property (nonatomic, strong) UIView *valueView;
@property (nonatomic, strong) UIButton *shareButton;

@property (nonatomic, strong) UIButton *loadButton;

@property (nonatomic, strong) UIButton *stateButton;

@property (nonatomic, assign) NSInteger stater;
@end

@implementation ZCPlayMusicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化数组
    self.listArr = [NSMutableArray array];
    NSArray *sendBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [[sendBox lastObject] stringByAppendingPathComponent:@"list.plist"];
    self.listArr = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    //随时监听列表的变化
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(list:) name:@"arr" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(play:) name:@"play" object:nil];
    //进度条监听
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pro:) name:@"pross" object:nil];
    
    //监听播放完毕playList
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(next:) name:@"end" object:nil];
    
     [ZCPlayMusicTool sharePlay].urlMusic = [[NSUserDefaults standardUserDefaults] objectForKey:@"url"];
    
    [self  creatReturn];
    [self creatbottomUI];
    [self creatTableView];
    
}

-(void)pro:(NSNotification *)not{
    
    [self.progress setProgress:[[ZCPlayMusicTool sharePlay].pross floatValue] animated:YES];
}

-(void)play:(NSNotification *)not{
    
    self.nameLabel.text = not.userInfo[@"name"];
    self.singerLabel.text = not.userInfo[@"nameSinge"];
}

-(void)list:(NSNotification *)not{
    
    self.listArr = not.userInfo[@"arr"];
    [self.tableView reloadData];
}

//创建列表
-(void)creatTableView{
    
    self.headButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.headButton.backgroundColor = [UIColor colorWithWhite:0.808 alpha:1.000];
    self.headButton.frame = CGRectMake(0, 0, WIDTH, HEIGHT - 100);
    self.headButton.hidden = YES;
    self.headButton.alpha = 0.5;
    [self.view addSubview:self.headButton];
    [self.headButton addTarget:self action:@selector(retu:) forControlEvents:UIControlEventTouchUpInside];

    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.rowHeight = 70;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    self.tableView.backgroundColor = [UIColor colorWithRed:0.802 green:1.000 blue:0.398 alpha:1.000];
    
    self.tableView.alpha = 0.9;
    self.tableView.hidden = YES;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-100);
        make.height.equalTo(@230);
    }];
}

-(void)retu:(UIButton *)bu{
    self.tableView.hidden = YES;
    self.headButton.hidden = YES;
    self.isList = YES;
}

//歌曲列表的点击方法
- (void)Ico:(UITapGestureRecognizer *)not{
    if(!self.isList){
        self.tableView.hidden = NO;
        self.headButton.hidden = NO;
    }else{
        self.tableView.hidden = YES;
        self.headButton.hidden = YES;
    }
    self.isList = ! self.isList;
}

-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *re = @"re";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:re];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:re];
    }
    if(self.listArr.count != 0){
        
        ZCMainModel *model = self.listArr [indexPath.row];
        cell.textLabel.text = model.name;
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.numberOfLines = 0;
        cell.detailTextLabel.text = model.singerName;
    }
    
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"播放列表";
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZCMainModel *model = self.listArr[indexPath.row];
   
    
    if(model.auditionList.count == 0) {
        
        UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"歌曲版权不支持" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alter animated:YES completion:nil];
        [self dismissViewControllerAnimated:YES completion:^{
        }];
        return;
    }
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:model.name,@"name",model.singerName,@"nameSinge",model.picUrl,@"heat",model.auditionList[0][@"url"],@"url",nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"play" object:self userInfo:dic];
    [ZCPlayMusicTool getPlay:model.auditionList[0][@"url"]];
    [ZCPlayMusicTool sharePlay].urlMusic = model.auditionList[0][@"url"];
    
    //改变按钮状态
    [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
}


//创建返回按钮
-(void)creatReturn{
    
    UIButton *bu = [UIButton buttonWithType:UIButtonTypeCustom];
    [bu addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [bu setImage:[UIImage imageNamed:@"iconfont-xiala"] forState:UIControlStateNormal];
    bu.layer.borderWidth = 1;
    bu.layer.borderColor = [UIColor whiteColor].CGColor;
    bu.alpha = 0.5;
    bu.backgroundColor = [UIColor colorWithRed:1.000 green:0.995 blue:0.839 alpha:1.000];
    bu.layer.cornerRadius = 25;
    bu.frame =CGRectMake(20, 50, 50, 50);
    [self.view addSubview:bu];

}

//退出的点击方法
-(void)click:(UIButton *)bu{
    
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    window.userInteractionEnabled = NO;
    
    // 1.动画隐藏
    [UIView animateWithDuration:0.5 animations:^{
        self.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        self.view.hidden = YES;
        window.userInteractionEnabled = YES;
    }];
    
    //点击返回的时候判断播放按钮的状态
    [[NSNotificationCenter defaultCenter] postNotificationName:@"chang" object:nil];
}
//显示UI
-(void)show{

    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    window.userInteractionEnabled = NO;
    // 1.添加播放界面
    self.view.frame = window.bounds;
    self.view.hidden = NO;
    [window addSubview:self.view];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1c06aa37a8154ae4bad9ef41e78fbd0b.jpg"]];
    //动画显示
   self.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    [UIView animateWithDuration:0.5 animations:^{
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        // 开始播放音乐
        //[self startPlayingMusic];
        window.userInteractionEnabled = YES;
    }];
    if([ZCPlayMusicTool sharePlay].isplay){
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
    }else{
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"iconfont-livesvg04-2"] forState:UIControlStateNormal];
    }
    
}
//创建播放界面
-(void)creatbottomUI{
    
    self.bottomView = [[UIView alloc] init];
    self.bottomView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.bottomView];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@100);
    }];
    
    
    self.perButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.perButton];
    [self.perButton setImage:[UIImage imageNamed:@"iconfont-bofangqishangyiqu"] forState:UIControlStateNormal];
    [self.perButton addTarget:self action:@selector(per:) forControlEvents:UIControlEventTouchUpInside];
    [self.perButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomView).offset(20);
        make.bottom.equalTo(self.bottomView).offset(-25);
        make.left.equalTo(self.bottomView).offset(100 * WIDTH / 375);
        make.width.equalTo(@35);
    }];
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.playButton];
    
    //判断按钮的样式
   

    [self.playButton addTarget:self action:@selector(playB:) forControlEvents:UIControlEventTouchUpInside];
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomView).offset(20);
        make.bottom.equalTo(self.bottomView).offset(-25);
        make.left.equalTo(self.bottomView).offset(165* WIDTH / 375);
        make.width.equalTo(@50);
    }];
    
    self.nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.nextButton];
    [self.nextButton setImage:[UIImage imageNamed:@"iconfont-bofangqixiayiqu"] forState:UIControlStateNormal];
    [self.nextButton addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    self.nextButton.tag = 1000000;
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomView).offset(20);
        make.bottom.equalTo(self.bottomView).offset(-25);
        make.left.equalTo(self.bottomView).offset(245* WIDTH / 375);
        make.width.equalTo(@35);
    }];
    //列表按钮
    self.listButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.listButton];
    [self.listButton addTarget:self action:@selector(Ico:) forControlEvents:UIControlEventTouchUpInside];
    [self.listButton setImage:[UIImage imageNamed:@"iconfont-bofangliebiao-2"] forState:UIControlStateNormal];
    [self.listButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomView).offset(20);
        make.bottom.equalTo(self.bottomView).offset(-25);
        make.left.equalTo(self.bottomView).offset(320 * WIDTH / 375);
        make.width.equalTo(@35);
    }];
    
    //歌曲
    self.nameLabel = [[UILabel alloc] init];
    [self.view addSubview:self.nameLabel];
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
   
    self.nameLabel.textColor = [UIColor colorWithRed:0.942 green:1.000 blue:0.298 alpha:1.000];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.bottom.equalTo(self.view).offset(-140);
        make.width.equalTo(@15);
        make.height.equalTo(@180);
    }];
    
    //歌手
    self.singerLabel = [[UILabel alloc] init];
    [self.view addSubview:self.singerLabel];
    self.singerLabel.textColor = [UIColor colorWithRed:0.942 green:1.000 blue:0.298 alpha:1.000];
    self.singerLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"nameSinge"];
    self.singerLabel.numberOfLines = 0;
    [self.singerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(45);
        make.bottom.equalTo(self.view).offset(-120);
        make.width.equalTo(@15);
        make.height.equalTo(@180);
    }];
   
    
    //音量View
    self.valueView = [[UIView alloc] init];
    self.valueView.userInteractionEnabled = YES;
    [self.view addSubview:self.valueView];
    [self.valueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-10);
        make.top.equalTo(self.view).offset(60);
        make.left.equalTo(self.view).offset(100);
        
        make.width.equalTo(@280);
        make.height.equalTo(@30);
    }];
    UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(wip:)];
    swip.numberOfTouchesRequired = 1;
    swip.direction = UISwipeGestureRecognizerDirectionRight;
    [self.valueView addGestureRecognizer:swip];
    
    UIImageView *va = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-cubanyinliang"]];
    [self.valueView addSubview:va];
    [va mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.valueView);
        make.top.equalTo(self.valueView).offset(5);
        make.bottom.equalTo(self.valueView).offset(0);
        make.width.equalTo(@15);
    }];
    
    
    //音量条
    self.slider = [[UISlider alloc] init];
    self.slider.minimumValue = 0;
    self.slider.maximumValue = 50;
    self.slider.value = 20;
    self.slider.hidden = YES;
    self.slider.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    [self.slider setUserInteractionEnabled:YES];
    self.slider.thumbTintColor = [UIColor orangeColor];
    [self.slider addTarget:self action:@selector(slde:) forControlEvents:UIControlEventTouchDragInside];
    [self.slider addTarget:self action:@selector(sldeEnd:) forControlEvents: UIControlEventTouchUpInside];
    [self.valueView addSubview:self.slider];
    [self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.valueView).offset(0);
        make.left.equalTo(self.valueView).offset(20);
        make.right.equalTo(self.valueView).offset(0);
        make.height.equalTo(@30);
    }];
    
    //进度条
    self.progress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    [self.bottomView addSubview:self.progress];
    [self.progress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.bottomView);
        make.height.equalTo(@5);
    }];
    self.progress.trackTintColor = [UIColor orangeColor];
    [self.progress setProgress:[[ZCPlayMusicTool sharePlay].pross floatValue] animated:YES];
    
    // 分享按钮
    self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.shareButton setImage:[UIImage imageNamed:@"iconfont-fenxiang-1"] forState:UIControlStateNormal];
    [self.view addSubview:self.shareButton];
    [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.bottom.equalTo(self.progress.mas_bottom).offset(-20);
        make.width.equalTo(@20);
        make.height.equalTo(@20);
    }];
    [self.shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    
    // 下载按钮
    self.loadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.loadButton setImage:[UIImage imageNamed:@"iconfont-xiazai-1"] forState:UIControlStateNormal];
    [self.view addSubview:self.loadButton];
    [self.loadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-5);
        make.bottom.equalTo(self.progress.mas_bottom).offset(-10);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
    }];
    [self.loadButton addTarget:self action:@selector(load:) forControlEvents:UIControlEventTouchUpInside];
    
    //播放状态
    self.stateButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.stateButton setImage:[UIImage imageNamed:@"iconfont-shunxuxunhuan"] forState:UIControlStateNormal];
    [self.bottomView addSubview:self.stateButton];
    [self.stateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView).offset(20);
        make.bottom.equalTo(self.bottomView).offset(-25);
        make.left.equalTo(self.bottomView).offset(25);
        make.width.equalTo(@35);
    }];
    [self.stateButton addTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];
    self.stater = 1;
    
}

//播放顺序状态
-(void)order:(UIButton *)button{
    [self.stateButton removeTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];
    [self.stateButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan"] forState:UIControlStateNormal];
    [self.stateButton addTarget:self action:@selector(single:) forControlEvents:UIControlEventTouchUpInside];
  
    UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, -40, 100, 40)];
    [self.view addSubview:shareLabel];
    [UILabel animateWithDuration:1 animations:^{
        shareLabel.frame = CGRectMake(150, 50, 100, 40);
        shareLabel.text = @"单曲循环";
        shareLabel.textAlignment = NSTextAlignmentCenter;
        shareLabel.textColor = [UIColor whiteColor];
    }];
    
    [UILabel animateWithDuration:1 animations:^{
        [UILabel setAnimationDelay:0.5];
        shareLabel.frame = CGRectMake(150, -40, 100, 40);
    }];
    
    self.stater = 2;
    
    
    
}
//单曲播放
-(void)single:(UIButton *)button{
    [self.stateButton removeTarget:self action:@selector(single:) forControlEvents:UIControlEventTouchUpInside];
    [self.stateButton setImage:[UIImage imageNamed:@"iconfont-suijibofang"] forState:UIControlStateNormal];
    [self.stateButton addTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, -40, 100, 40)];
    [self.view addSubview:shareLabel];
    [UILabel animateWithDuration:1 animations:^{
        shareLabel.frame = CGRectMake(150, 50, 100, 40);
        shareLabel.text = @"随机播放";
        shareLabel.textAlignment = NSTextAlignmentCenter;
        shareLabel.textColor = [UIColor whiteColor];
    }];
    
    [UILabel animateWithDuration:1 animations:^{
        [UILabel setAnimationDelay:0.5];
        shareLabel.frame = CGRectMake(150, -40, 100, 40);
    }];
    self.stater = 3;
    
    
}
//随机播放
-(void)random:(UIButton *)button{
    [self.stateButton removeTarget:self action:@selector(random:) forControlEvents:UIControlEventTouchUpInside];
    [self.stateButton setImage:[UIImage imageNamed:@"iconfont-shunxuxunhuan"] forState:UIControlStateNormal];
    [self.stateButton addTarget:self action:@selector(order:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, -40, 100, 40)];
    [self.view addSubview:shareLabel];
    [UILabel animateWithDuration:1 animations:^{
        shareLabel.frame = CGRectMake(150, 50, 100, 40);
        shareLabel.text = @"顺序播放";
        shareLabel.textAlignment = NSTextAlignmentCenter;
        shareLabel.textColor = [UIColor whiteColor];
    }];
    [UILabel animateWithDuration:1 animations:^{
        [UILabel setAnimationDelay:0.5];
        shareLabel.frame = CGRectMake(150, -40, 100, 40);
    }];
    
    self.stater = 1;
    
}






//下载
- (void)load:(UIButton *)button{
    
    NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
    NSString *str = [name stringByAppendingString:@".mp3"];
    NSLog(@"%@",str);
    NSString *sing = [[NSUserDefaults standardUserDefaults] objectForKey:@"nameSinge"];

    [[ZCDownLoadTool shareDownLoad] addDownloadTask:str urlStr:[ZCPlayMusicTool sharePlay].urlMusic singer:sing];
}



// 分享
- (void)share:(UIButton *)button
{
    NSString *url = [ZCPlayMusicTool sharePlay].urlMusic;
    NSString *detaileText = [NSString stringWithFormat:@"%@-%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"name"],[[NSUserDefaults standardUserDefaults] objectForKey:@"nameSinge"]];
    NSString *shareText = [detaileText stringByAppendingFormat:@"\n%@",url];
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:shareText
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
                                       delegate:self];
}
// 回调方法
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {

        UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, -40, 100, 40)];
        [self.view addSubview:shareLabel];
        [UILabel animateWithDuration:1 animations:^{
            shareLabel.frame = CGRectMake(150, 50, 100, 40);
            shareLabel.text = @"分享成功";
            shareLabel.textAlignment = NSTextAlignmentCenter;
            shareLabel.textColor = [UIColor whiteColor];
        }];
        
        [UILabel animateWithDuration:2 animations:^{
            [UILabel setAnimationDelay:2];
            shareLabel.frame = CGRectMake(150, -40, 100, 40);
        }];
    }
    
}
//音量控制
-(void)slde:(UIButton *)bu{
    [ZCPlayMusicTool sharePlay].player.volume = self.slider.value;
}
-(void)sldeEnd:(UIButton *)bu{
    self.slider.hidden = YES;
}
-(void)wip:(UISwipeGestureRecognizer *)swi{
    self.slider.hidden = NO;
}

-(void)per:(UIButton *)bu{
    
    if(self.stater == 2){
        
        [ZCPlayMusicTool getSinglePlay:[ZCPlayMusicTool sharePlay].urlMusic];
        
    }else if( self.stater == 3){
    
        NSInteger i = arc4random()%self.listArr.count;
        NSLog(@"%ld",i);
        ZCMainModel * model = self.listArr[i];
        
        [ZCPlayMusicTool  getPlay:model.auditionList[0][@"url"]];
        if(model.auditionList.count == 0) {
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"下一首歌曲版权不支持" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alter animated:YES completion:nil];
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            return;
        }
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:model.name,@"name",model.singerName,@"nameSinge",model.picUrl,@"heat",model.auditionList[0][@"url"],@"url",nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"play" object:self userInfo:dic];
        
        [ZCPlayMusicTool getSinglePlay:model.auditionList[0][@"url"]];
        
        [ZCPlayMusicTool sharePlay].urlMusic = model.auditionList[0][@"url"];
        //改变按钮状态
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
        [self.progress setProgress:0 animated:YES];
        
        
    }else{
        
        ZCMainModel *model ;
        for (NSInteger i = 0; i < self.listArr.count; i++) {
            ZCMainModel *model1 = self.listArr[i];
            if(model1.auditionList.count == 0)break;
            
            if([[ZCPlayMusicTool sharePlay].urlMusic isEqualToString:model1.auditionList[0][@"url"]]){
                if(i-1 < 0){
                    
                    UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"前面没有歌曲了" preferredStyle:UIAlertControllerStyleAlert];
                    [self presentViewController:alter animated:YES completion:nil];
                    
                    [self dismissViewControllerAnimated:YES completion:^{
                    }];
                    
                    return;
                }
                model = self.listArr[i-1];
                break;
            }
        }
        
        if(model.auditionList.count == 0) {
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"歌曲版权不支持" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alter animated:YES completion:nil];
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            return;
        }
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:model.name,@"name",model.singerName,@"nameSinge",model.picUrl,@"heat",model.auditionList[0][@"url"],@"url",nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"play" object:self userInfo:dic];
        
        [ZCPlayMusicTool getPlay:model.auditionList[0][@"url"]];
        
        
        [ZCPlayMusicTool sharePlay].urlMusic = model.auditionList[0][@"url"];
        
        //改变按钮状态
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
        [self.progress setProgress:0 animated:YES];

    }
}
- (void)next:(UIButton *)bu{
    
    if (self.stater == 2) {
        
        [ZCPlayMusicTool getSinglePlay:[ZCPlayMusicTool sharePlay].urlMusic];
        
    }else if (self.stater == 3){
        
        NSInteger i = arc4random()%self.listArr.count;
        NSLog(@"%ld",i);
        ZCMainModel * model = self.listArr[i];
        [ZCPlayMusicTool  getPlay:model.auditionList[0][@"url"]];
        if(model.auditionList.count == 0) {
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"下一首歌曲版权不支持" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alter animated:YES completion:nil];
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            return;
        }
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:model.name,@"name",model.singerName,@"nameSinge",model.picUrl,@"heat",model.auditionList[0][@"url"],@"url",nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"play" object:self userInfo:dic];
    
        [ZCPlayMusicTool getSinglePlay:model.auditionList[0][@"url"]];
        [ZCPlayMusicTool sharePlay].urlMusic = model.auditionList[0][@"url"];
        
        //改变按钮状态
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
        [self.progress setProgress:0 animated:YES];
        
    }else{
        ZCMainModel *model ;
        for (NSInteger i = 0; i < self.listArr.count; i++) {
            
            ZCMainModel *model1 = self.listArr[i];
            if(model1.auditionList.count == 0)break;
            
            if([[ZCPlayMusicTool sharePlay].urlMusic isEqualToString:model1.auditionList[0][@"url"]]){
                if(i+1 >= self.listArr.count){
                    UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"已经是最后一首歌了" preferredStyle:UIAlertControllerStyleAlert];
                    [self presentViewController:alter animated:YES completion:nil];
                    
                    [self dismissViewControllerAnimated:YES completion:^{
                    }];
                    return;
                }
                model = self.listArr[i+1];
                break;
            }
        }
        
        if(model.auditionList.count == 0) {
            UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"消息" message:@"下一首歌曲版权不支持" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alter animated:YES completion:nil];
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            return;
        }
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:model.name,@"name",model.singerName,@"nameSinge",model.picUrl,@"heat",model.auditionList[0][@"url"],@"url",nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"play" object:self userInfo:dic];
        
        [ZCPlayMusicTool getPlay:model.auditionList[0][@"url"]];
        
        
        [ZCPlayMusicTool sharePlay].urlMusic = model.auditionList[0][@"url"];
        
        //改变按钮状态
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
        
        [self.progress setProgress:0 animated:YES];
    }
    
    
}

//播放开始
-(void)playB:(UIButton *)bu{

    if(![ZCPlayMusicTool sharePlay].isplay){
        [self.playButton  setBackgroundImage:[UIImage imageNamed:@"iconfont-iconfont32"] forState:UIControlStateNormal];
    
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"isLocal"]){
            //播放音乐
            [ZCPlayMusicTool  getPlay:[ZCPlayMusicTool sharePlay].urlMusic];
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLocal"];
        }else{
            [[ZCPlayMusicTool sharePlay].player play];
        }
        
    }else{
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"iconfont-livesvg04-2"] forState:UIControlStateNormal];
        [[ZCPlayMusicTool sharePlay].player pause];
    }
    [ZCPlayMusicTool sharePlay].isplay = ![ZCPlayMusicTool sharePlay].isplay;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
}




@end
